<template>
	<view class="page-e tn-safe-area-inset-bottom">

		<!-- 顶部自定义导航 -->
		<!-- 	<tn-nav-bar :isBack="false" :bottomShadow="false" backgroundColor="none">
      <view class="custom-nav tn-flex tn-flex-col-center tn-flex-row-left" @click="tn('')">
        <view class="custom-nav__back">
          <text class="tn-text-bold tn-text-xl tn-color-black">个人中心</text>
        </view>
      </view>
    </tn-nav-bar> -->

		<view class="top-backgroup">
			<image src='https://tnuiimage.tnkjapp.com/my/my-bg4.png' mode='widthFix' class='backgroud-image'></image>
		</view>

		<view class="tn-margin-left tn-margin-right" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
			<!-- 图标logo/头像 -->
			<view class="tn-flex tn-flex-row-between tn-flex-col-center tn-margin-bottom" style="margin-top: -450rpx;"
				@click="toMeInfoSet()">
				<view v-if="vuex_user">
					<view class="justify-content-item">
						<view class="tn-flex tn-flex-col-center tn-flex-row-left">
							<view class="logo-pic tn-shadow">
								<view class="logo-image">

									<image class="tn-shadow-blur"
										style="width: 110rpx;height: 110rpx;background-size: cover;overflow: hidden;"
										:src="vuex_user.headImg"></image>

								</view>
							</view>
							<view class="tn-padding-right">
								<view class="tn-padding-right tn-padding-left-sm">
									<text
										class="tn-color-wallpaper tn-text-xl tn-text-bold">{{vuex_user.username}}</text>
									<text class=" tn-round tn-text-xs tn-bg-red tn-color-white tn-margin-left-sm"
										style="padding: 10rpx 20rpx;" v-if="!vuex_user.email">
										未绑定邮箱
									</text>
								</view>
								<view class="tn-padding-right tn-padding-top-xs tn-padding-left-sm tn-text-ellipsis">
									<text
										class="tn-color-gray">{{vuex_user.email?vuex_user.email:'ID：'+vuex_user.userId}}</text>
									<!-- <text class="tn-color-gray tn-padding-left-sm tn-text-sm">ID:{{vuex_user.userId}}</text> -->
								</view>
							</view>

						</view>
					</view>

				</view>

				<view v-if="vuex_user" class="justify-content-item">
					<view class="tn-icon-right tn-color-gray">
					</view>
				</view>
			</view>

			<!-- 没有授权，则显示这个授权按钮-->
			<view v-if="!vuex_user" class="tn-flex tn-flex-row-between" @click="tn('/pageA/login/login')">
				<view class="tn-flex-1 justify-content-item tn-margin-xs tn-text-center">
					<tn-button shape="round" backgroundColor="#1D2541" fontColor="#ffffff" padding="20rpx 0" width="40%"
						shadow>
						<text class="tn-icon-wechat tn-padding-right-xs tn-text-xl"></text>
						<text class="">授权登录</text>
					</tn-button>
				</view>
			</view>

			<view class="tn-margin-top-xl">
				<view class="button-number tn-flex tn-flex-row-between tn-flex-col-center tn-shadow-blur"
					style="background: linear-gradient(-120deg, #3E445A, #31374A, #2B3042, #262B3C);">

					<view class="tn-margin-left">
						<view v-if="vuex_user" class='title' style="color: #F1C68E;">
							<text class="tn-text-bold tn-text-xl">{{vuex_user.score}} 积分</text>

							<text class="tn-icon-vip-text tn-text-center"
								style="position: absolute;margin: -22rpx 0 0 0;font-size: 92rpx;"></text>
						</view>
						<view class='tn-color-white tn-text-sm tn-padding-top-sm'>邀请好友赚取更多积分</view>
					</view>
					<view class="tn-margin-right">
						<tn-button shape="round" backgroundColor="#F1C68E" fontColor="#634738" padding="10rpx 0"
							width="160rpx" shadow open-type="share">
							<text class="tn-icon-vip tn-padding-right-sm tn-text-lg"></text>
							<text class="tn-text-bold">邀 请</text>
						</tn-button>
					</view>

				</view>
			</view>

			<!-- 图标或者图片布局，有需要直接显示出来即可，预留的布局 -->
			<!-- 方式15  start-->
			<!-- <view class="tn-flex tn-flex-row-between tn-bg-white wallpaper-shadow tn-margin-top-xl">
        <view class="tn-padding-sm tn-margin-xs" @click="tn('/minePages/release')">
          <view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center tn-margin-left">
            <view class="icon15__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-shadow-blur" style="background-color: #F3F2F7;color: #7C8191;">
              <view class="tn-icon-calendar"></view>
            </view> 
            <view class="icon5__item--icon tn-flex tn-flex-row-center tn-flex-col-center" style="background-image:url('https://cdn.nlark.com/yuque/0/2022/png/280373/1666764808285-assets/web-upload/b83d1b36-7355-4f36-bc02-9f06b8c0867c.png');background-size:100% 100%;background-size: cover;">
            </view>
            <view class="tn-text-center">
              <text class="tn-text-ellipsis">发 布</text>
            </view>
          </view>
        </view>
        <view class="tn-padding-sm tn-margin-xs" @click="tn('/minePages/collect')">
          <view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
            <view class="icon15__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-shadow-blur" style="background-color: #F3F2F7;color: #7C8191;">
              <view class="tn-icon-star"></view>
            </view> 
            <view class="icon5__item--icon tn-flex tn-flex-row-center tn-flex-col-center" style="background-image:url('https://cdn.nlark.com/yuque/0/2022/png/280373/1666764788528-assets/web-upload/955b13dd-7715-4627-b8cc-04ae3d85051a.png');background-size:100% 100%;background-size: cover;">
            </view>
            <view class="tn-text-center">
              <text class="tn-text-ellipsis">创 作</text>
            </view>
          </view>
        </view>
        <view class="tn-padding-sm tn-margin-xs">
          <view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center tn-margin-right">
            <view class="icon15__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-shadow-blur" style="background-color: #F3F2F7;color: #7C8191;">
              <view class="tn-icon-download"></view>
            </view> 
            <view class="icon5__item--icon tn-flex tn-flex-row-center tn-flex-col-center" style="background-image:url('https://cdn.nlark.com/yuque/0/2022/png/280373/1666764788454-assets/web-upload/397ee31e-b1b1-44ea-bb4c-0436eee867e5.png');background-size:100% 100%;background-size: cover;">
            </view>
            <view class="tn-text-center">
              <text class="tn-text-ellipsis">下 载</text>
            </view>
          </view>
        </view>
      </view> -->
			<!-- 方式15 end-->


			<!-- 方式20 start-->
			<!-- 处理很烦的告警问题 -->
			<!--  #ifdef  MP-WEIXIN -->
			<view v-if="pieceAboutListData" v-for="(pieceItem,pieceIndex) in pieceAboutListData" :key="pieceIndex"
				class="tn-flex">
				<!--  #endif -->
				<!--  #ifndef  MP-WEIXIN -->
				<view v-if="pieceAboutListData" v-for="(pieceItem,pieceIndex) in pieceAboutListData"
					:key="'piece-'+pieceIndex" class="tn-flex">
					<!--  #endif -->

					<view v-for="(item,itemIndex) in pieceItem" class="tn-flex-1 wallpaper-shadow tn-bg-white"
						:key="item.id" @click="clickAbout(item)" style="margin: 50rpx 15rpx 0 0;padding: 30rpx 0;">
						<view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
							<!-- <view
							class="icon20__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-shadow-blur tn-bg-orangered tn-color-white">
							<view class="tn-icon-computer-fill"></view>
						</view> -->
							<view class="icon5__item--icon tn-flex tn-flex-row-center tn-flex-col-center"
								:style="'background-image:url('+item.icon+');background-size:100% 100%;background-size: cover;'">
							</view>
							<view class="tn-text-center" style="font-size: 30rpx;">
								<view class="tn-text-ellipsis">{{item.name}}</view>
							</view>
						</view>
					</view>

				</view>

				<!-- 更多信息-->
				<!-- 方式12 start-->
				<view class="wallpaper-shadow tn-margin-top-lg tn-padding-top-sm tn-padding-bottom-sm tn-bg-white">
					<view v-for="(groupItem,groupIndex) in columnAboutListData" :key="groupIndex"
						class="tn-flex tn-flex-row-center tn-radius tn-padding-top">
						<view v-for="(item,index) in groupItem" :key="item.id"
							class="tn-padding-sm tn-margin-xs tn-radius">

							<button v-if="item.type === 5" :open-type="item.url" class="tn-button--clear-style">
								<view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
									<view
										class="icon12__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-bg-grey--light">
										<view :class="item.icon + ' tn-color-wallpaper'"></view>
									</view>
									<view class="tn-text-center">
										<text class="tn-text-ellipsis">{{item.name}}</text>
									</view>
								</view>
							</button>

							<view v-else @click="clickAbout(item)"
								class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
								<view
									class="icon12__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-bg-grey--light">
									<view :class="item.icon + ' tn-color-wallpaper'"></view>
								</view>
								<view class="tn-text-center">
									<text class="tn-text-ellipsis">{{item.name}}</text>
								</view>

							</view>
						</view>
					</view>

				</view>


				<view v-if="rowAboutListData" v-for="(groupItem,index) in rowAboutListData" :key="index"
					class="wallpaper-shadow tn-margin-top-lg tn-padding-top-sm tn-padding-bottom-sm">
					<tn-list-cell v-for="item in groupItem" :key="item.id" :hover="true" :unlined="true" :radius="true"
						:fontSize="30">

						<button v-if="item.type === 5" class="tn-flex tn-flex-col-center tn-button--clear-style"
							:open-type="item.url">
							<view class="icon1__item--icon tn-flex tn-flex-row-center tn-flex-col-center"
								style="color: #7C8191;">
								<view v-if="item.icon">
									<view v-if="item.icon.indexOf('tn-icon')===0" :class="item.icon"></view>
									<image v-else-if="item.icon.indexOf('http')===0" style="width: 40rpx;height: 40rpx;"
										:src="item.icon">
									</image>
								</view>
							</view>
							<view class="tn-flex tn-flex-row-between" style="width: 100%;">
								<view class="tn-margin-left-sm">{{item.name}}</view>
								<view class="tn-color-gray tn-icon-right"></view>
							</view>
						</button>

						<view v-else class="tn-flex tn-flex-col-center" @click="clickAbout(item)">
							<view class="icon1__item--icon tn-flex tn-flex-row-center tn-flex-col-center"
								style="color: #7C8191;">
								<view v-if="item.icon">
									<view v-if="item.icon.indexOf('tn-icon')===0" :class="item.icon"></view>
									<image v-else-if="item.icon.indexOf('http')===0" style="width: 40rpx;height: 40rpx;"
										:src="item.icon">
									</image>
								</view>
							</view>
							<view class="tn-margin-left-sm tn-flex-1">{{item.name}}</view>
							<view v-if="item.type !== 4" class="tn-color-gray tn-icon-right"></view>
						</view>

					</tn-list-cell>
				</view>

				<view v-if="vuex_user" class="wallpaper-shadow">
					<tn-list-cell :hover="true" :unlined="true" :radius="true" :fontSize="32" @click="clickLogout">
						<view class="tn-flex tn-flex-col-center">
							<view class=" tn-flex-1 tn-color-red tn-text-center">退出登录</view>
						</view>
					</tn-list-cell>
				</view>

			</view>
			<view class='tn-tabbar-height'></view>

		</view>
</template>

<script>
	import {
		getTotalScore
	} from "@/api/score.js"
	import ws from "@/api/websocket.js"
	import {
		toLogout
	} from '@/api/auth.js';

	import {
		getAboutList
	} from '@/api/about.js';

	import {
		loginRouter,
		loginVerify
	} from '@/utils/loginUtil.js';

	export default {
		name: 'Mine',
		data() {
			return {
				pieceAboutListData: [],
				rowAboutListData: [],
				columnAboutListData: []
			}
		},
		created() {
			this.getRowAboutListData()
		},
		methods: {
			updateUserScore() {
				if (!this.vuex_user) {
					return
				}
				getTotalScore().then(res => {
					let userInfo = this.vuex_user
					userInfo.score = res.data

					this.$t.vuex('vuex_user', {
						...this.vuex_user,
						...userInfo
					})
				})
			},
			// 点击个人信息设置
			toMeInfoSet() {
				loginRouter("/pageA/set/set")
			},
			checkAboutLogin(login, url) {
				if (login === 1) {
					loginRouter(url)
				} else {
					this.tn(url)
				}
			},
			// 处理关于按钮点击事件
			clickAbout(e) {
				if (e.type === 1) {
					// 1、富文本类型
					this.checkAboutLogin(e.login, `/pageA/about/about?id=${e.id}`)
				} else if (e.type === 2) {
					// 2、内部链接
					this.checkAboutLogin(e.login, e.url)
				} else if (e.type === 3) {
					// 3、外部链接
					this.checkAboutLogin(e.login, `/pageB/article/article?url=${e.url}`)
				} else if (e.type === 4) {
					// 4、弹窗提示
					if (!e.login || loginVerify()) {
						uni.showModal({
							title: e.name,
							content: e.shortContent
						})
					}
				}
			},
			getRowAboutListData() {
				getAboutList().then(res => {
					// 行数据
					let rowList = []
					// 列数据
					let columnList = []
					// 块数据
					let pieceList = []
					// 收集三者
					for (const item of res.data) {
						if (item.layoutType === 0) {
							rowList.push(item)
						} else if (item.layoutType === 1) {
							columnList.push(item)
						} else if (item.layoutType === 2) {
							pieceList.push(item)
						}
					}
					// 行：3个一组
					let rowGroupNum = 3;
					for (var i = 0, len = rowList.length; i < len; i += rowGroupNum) {
						this.rowAboutListData.push(rowList.slice(i, i + rowGroupNum));
					}

					// 列：4个一组
					let columnGroupNum = 4;
					for (var i = 0, len = columnList.length; i < len; i += columnGroupNum) {
						this.columnAboutListData.push(columnList.slice(i, i + columnGroupNum));
					}

					// 块：3个一组
					let pieceGroupNum = 3;
					for (var i = 0, len = pieceList.length; i < len; i += pieceGroupNum) {
						this.pieceAboutListData.push(pieceList.slice(i, i + pieceGroupNum));
					}
				})
			},
			// 退出登录
			clickLogout() {
				toLogout().finally(() => {
					this.$t.vuex('vuex_user', null)
					this.$t.vuex('vuex_user_msg_list', [])
					this.$t.vuex('vuex_user_msg_list_red_tip', false)
					ws.closeWebSocket()
				})

			},
			// 跳转
			tn(e) {
				uni.navigateTo({
					url: e,
				});
			},
			//拨打固定电话
			callPhoneNumber() {
				uni.makePhoneCall({
					phoneNumber: "15627915168",
				});
			},
			// 复制开源地址
			copySource() {
				wx.vibrateShort();
				uni.setClipboardData({
					data: "xxxx",
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.page-e {
		max-height: 100vh;
	}

	/* 底部安全边距 start*/
	.tn-tabbar-height {
		min-height: 20rpx;
		height: calc(40rpx + env(safe-area-inset-bottom) / 2);
		height: calc(40rpx + constant(safe-area-inset-bottom));
	}

	.tn-color-wallpaper {
		color: #1D2541;
	}


	/* 自定义导航栏内容 start */
	.custom-nav {
		height: 100%;

		&__back {
			margin: auto 30rpx;
			font-size: 40rpx;
			margin-right: 10rpx;
			flex-basis: 5%;
			width: 100rpx;
			position: absolute;
		}
	}

	/* 自定义导航栏内容 end */

	/* 顶部背景图 start */
	.top-backgroup {
		height: 450rpx;
		z-index: -1;

		.backgroud-image {
			width: 100%;
			height: 450rpx;
			z-index: -1;
		}
	}

	/* 顶部背景图 end */


	/* 图标容器5 start */
	.icon5 {
		&__item {
			// width: 30%;
			background-color: #FFFFFF;
			border-radius: 10rpx;
			padding: 0rpx;
			margin: 0rpx;
			transform: scale(1);
			transition: transform 0.3s linear;
			transform-origin: center center;

			&--icon {
				width: 96rpx;
				height: 96rpx;
				border-radius: 50%;
				margin-bottom: 18rpx;
				position: relative;
				z-index: 1;
			}
		}
	}

	/* 用户头像 start */
	.logo-image {
		width: 110rpx;
		height: 110rpx;
		position: relative;
		overflow: hidden;
		border-radius: 50%;
	}

	.logo-pic {
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border: 8rpx solid rgba(255, 255, 255, 0.05);
		box-shadow: 0rpx 0rpx 80rpx 0rpx rgba(0, 0, 0, 0.15);
		border-radius: 50%;
		overflow: hidden;
		// background-color: #FFFFFF;
	}

	/* 页面阴影 start*/
	.wallpaper-shadow {
		border-radius: 15rpx;
		box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.07);
	}

	/* 页面阴影 end*/

	/* 图标容器15 start */
	.icon15 {
		&__item {
			width: 30%;
			background-color: #FFFFFF;
			border-radius: 10rpx;
			padding: 30rpx;
			margin: 20rpx 10rpx;
			transform: scale(1);
			transition: transform 0.3s linear;
			transform-origin: center center;

			&--icon {
				width: 100rpx;
				height: 100rpx;
				font-size: 60rpx;
				border-radius: 50%;
				margin-bottom: 18rpx;
				position: relative;
				z-index: 1;

				&::after {
					content: " ";
					position: absolute;
					z-index: -1;
					width: 100%;
					height: 100%;
					left: 0;
					bottom: 0;
					border-radius: inherit;
					opacity: 1;
					transform: scale(1, 1);
					background-size: 100% 100%;


				}
			}
		}
	}

	/* 图标容器12 start */
	.tn-three {
		position: absolute;
		top: 50%;
		right: 50%;
		bottom: 50%;
		left: 50%;
		transform: translate(-38rpx, -16rpx) rotateX(30deg) rotateY(20deg) rotateZ(-30deg);
		text-shadow: -1rpx 2rpx 0 #f0f0f0, -2rpx 4rpx 0 #f0f0f0, -10rpx 20rpx 30rpx rgba(0, 0, 0, 0.2);
	}

	.icon20 {
		&__item {
			width: 30%;
			background-color: #FFFFFF;
			border-radius: 10rpx;
			padding: 30rpx;
			margin: 20rpx 10rpx;
			transform: scale(1);
			transition: transform 0.3s linear;
			transform-origin: center center;

			&--icon {
				width: 100rpx;
				height: 100rpx;
				font-size: 60rpx;
				border-radius: 50%;
				margin-bottom: 18rpx;
				position: relative;
				z-index: 1;

				&::after {
					content: " ";
					position: absolute;
					z-index: -1;
					width: 100%;
					height: 100%;
					left: 0;
					bottom: 0;
					border-radius: inherit;
					opacity: 1;
					transform: scale(1, 1);
					background-size: 100% 100%;
					background-image: url(https://tnuiimage.tnkjapp.com/cool_bg_image/icon_bg.png);
				}
			}
		}
	}


	/* 积分数字 */
	.button-number {
		width: 100%;
		height: 150rpx;
		border-radius: 15rpx;
		position: relative;
		z-index: 1;

		&::after {
			content: " ";
			position: absolute;
			z-index: -1;
			width: 100%;
			height: 100%;
			left: 0;
			bottom: 0;
			border-radius: inherit;
			opacity: 1;
			transform: scale(1, 1);
			background-size: 100% 100%;
			background-image: url(https://tnuiimage.tnkjapp.com/cool_bg_image/icon_bg.png);
		}
	}


	/* 图标容器12 start */
	.icon12 {
		&__item {
			width: 30%;
			background-color: #FFFFFF;
			border-radius: 10rpx;
			padding: 30rpx;
			margin: 20rpx 10rpx;
			transform: scale(1);
			transition: transform 0.3s linear;
			transform-origin: center center;

			&--icon {
				width: 15rpx;
				height: 15rpx;
				font-size: 50rpx;
				border-radius: 50%;
				margin-bottom: 38rpx;
				position: relative;
				z-index: 1;

				&::after {
					content: " ";
					position: absolute;
					z-index: -1;
					width: 100%;
					height: 100%;
					left: 0;
					bottom: 0;
					border-radius: inherit;
					opacity: 1;
					transform: scale(1, 1);
					background-size: 100% 100%;

				}
			}
		}
	}

	/* 图标容器1 start */
	.icon1 {
		&__item {
			// width: 30%;
			background-color: #FFFFFF;
			border-radius: 10rpx;
			padding: 30rpx;
			margin: 20rpx 10rpx;
			transform: scale(1);
			transition: transform 0.3s linear;
			transform-origin: center center;

			&--icon {
				width: 40rpx;
				height: 40rpx;
				font-size: 40rpx;
				border-radius: 50%;
				position: relative;
				z-index: 1;

				&::after {
					content: " ";
					position: absolute;
					z-index: -1;
					width: 100%;
					height: 100%;
					left: 0;
					bottom: 0;
					border-radius: inherit;
					opacity: 1;
					transform: scale(1, 1);
					background-size: 100% 100%;
					background-image: url(https://tnuiimage.tnkjapp.com/cool_bg_image/icon_bg.png);
				}
			}
		}
	}

	/* 图标容器1 end */
</style>